home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / vbench / vbench.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-07-13  |  14.1 KB  |  458 lines

  1. VERSION 2.00
  2. Begin Form Vbench 
  3.    BackColor       =   &H00C0C0C0&
  4.    Caption         =   "VBench"
  5.    ClientHeight    =   3228
  6.    ClientLeft      =   1584
  7.    ClientTop       =   660
  8.    ClientWidth     =   5172
  9.    Height          =   3648
  10.    Left            =   1536
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   3228
  13.    ScaleWidth      =   5172
  14.    Top             =   288
  15.    Width           =   5268
  16.    Begin TextBox Text1 
  17.       Height          =   372
  18.       Index           =   4
  19.       Left            =   2520
  20.       TabIndex        =   8
  21.       Text            =   "Text1"
  22.       Top             =   2160
  23.       Width           =   2412
  24.    End
  25.    Begin TextBox Text1 
  26.       Height          =   372
  27.       Index           =   3
  28.       Left            =   2520
  29.       TabIndex        =   7
  30.       Text            =   "Text1"
  31.       Top             =   1680
  32.       Width           =   2412
  33.    End
  34.    Begin TextBox Text1 
  35.       Height          =   372
  36.       Index           =   2
  37.       Left            =   2520
  38.       TabIndex        =   6
  39.       Text            =   "Text1"
  40.       Top             =   1200
  41.       Width           =   2412
  42.    End
  43.    Begin TextBox Text1 
  44.       Height          =   372
  45.       Index           =   1
  46.       Left            =   2520
  47.       TabIndex        =   5
  48.       Text            =   "Text1"
  49.       Top             =   720
  50.       Width           =   2412
  51.    End
  52.    Begin TextBox Text1 
  53.       Height          =   372
  54.       Index           =   0
  55.       Left            =   2520
  56.       TabIndex        =   4
  57.       Text            =   "Text1"
  58.       Top             =   240
  59.       Width           =   2412
  60.    End
  61.    Begin CommandButton Command1 
  62.       Caption         =   "E&xit"
  63.       Height          =   372
  64.       Index           =   3
  65.       Left            =   3840
  66.       TabIndex        =   3
  67.       Top             =   2760
  68.       Width           =   1092
  69.    End
  70.    Begin CommandButton Command1 
  71.       Caption         =   "&Populate"
  72.       Height          =   372
  73.       Index           =   2
  74.       Left            =   2640
  75.       TabIndex        =   2
  76.       Top             =   2760
  77.       Width           =   1092
  78.    End
  79.    Begin CommandButton Command1 
  80.       Caption         =   "&Select"
  81.       Height          =   372
  82.       Index           =   1
  83.       Left            =   1440
  84.       TabIndex        =   1
  85.       Top             =   2760
  86.       Width           =   1092
  87.    End
  88.    Begin CommandButton Command1 
  89.       Caption         =   "&Update"
  90.       Height          =   372
  91.       Index           =   0
  92.       Left            =   240
  93.       TabIndex        =   0
  94.       Top             =   2760
  95.       Width           =   1092
  96.    End
  97.    Begin Label Label1 
  98.       BackColor       =   &H00C0C0C0&
  99.       Caption         =   "Parameter QueryDef"
  100.       ForeColor       =   &H00FF0000&
  101.       Height          =   252
  102.       Index           =   4
  103.       Left            =   240
  104.       TabIndex        =   13
  105.       Top             =   2160
  106.       Width           =   2412
  107.    End
  108.    Begin Label Label1 
  109.       BackColor       =   &H00C0C0C0&
  110.       Caption         =   "Static QueryDef"
  111.       ForeColor       =   &H00FF0000&
  112.       Height          =   252
  113.       Index           =   3
  114.       Left            =   240
  115.       TabIndex        =   12
  116.       Top             =   1680
  117.       Width           =   2412
  118.    End
  119.    Begin Label Label1 
  120.       BackColor       =   &H00C0C0C0&
  121.       Caption         =   "Inline VB SQL"
  122.       ForeColor       =   &H00FF0000&
  123.       Height          =   252
  124.       Index           =   2
  125.       Left            =   240
  126.       TabIndex        =   11
  127.       Top             =   1200
  128.       Width           =   2412
  129.    End
  130.    Begin Label Label1 
  131.       BackColor       =   &H00C0C0C0&
  132.       Caption         =   "Dynaset FindFirst"
  133.       ForeColor       =   &H00FF0000&
  134.       Height          =   252
  135.       Index           =   1
  136.       Left            =   240
  137.       TabIndex        =   10
  138.       Top             =   720
  139.       Width           =   2412
  140.    End
  141.    Begin Label Label1 
  142.       BackColor       =   &H00C0C0C0&
  143.       Caption         =   "ISAM Table Seek"
  144.       ForeColor       =   &H00FF0000&
  145.       Height          =   252
  146.       Index           =   0
  147.       Left            =   240
  148.       TabIndex        =   9
  149.       Top             =   240
  150.       Width           =   2412
  151.    End
  152. 'Declarations
  153. Option Explicit
  154. Dim db As database
  155. Dim tbl As Table
  156. Dim dyna As dynaset
  157. Dim qd As querydef
  158. Dim foo As Integer
  159. Declare Function GetTickCount Lib "User" () As Long
  160. Sub CloseDb ()
  161. On Error Resume Next
  162.     dyna.Close
  163.     tbl.Close
  164.     qd.Close
  165.     db.Close
  166.     DoEvents
  167. End Sub
  168. Sub Command1_Click (Index As Integer)
  169. Dim TimeCount As Long, TimeStart As Long
  170. Dim foobar As Integer, foo As Integer
  171. ReDim cost(5) As Double
  172. TimeCount = 0
  173. 'Set the hourglass
  174. Screen.MousePointer = 11
  175. Select Case Index
  176. 'Update Operations ======================================
  177. 'The objective here is to examine 1000 out of 10,000 records,
  178. 'and modify those that match a given criteria - about 200 writes
  179. Case 0
  180.     Me.Caption = "VBench: Update Operation Benchmarks"
  181.     FileCopy "C:\vb\IoTest.Mdb", "C:\vb\IoTest.Bak"
  182.     'Seeks and indexed sequential updates ---------------
  183.     'Open the database logicals
  184.     OpenDb
  185.     'Start the clock
  186.     TimeStart = GetTickCount()
  187.     'Use transactions for speed
  188.     BeginTrans
  189.     'Jump to first ID using a fast seek
  190.     tbl.Seek ">=", 5000
  191.     'Continue searching till eof or break
  192.     Do Until tbl.EOF
  193.     'Test if reached top of range
  194.     If tbl!id < 6000 Then
  195.         'Test if record meets change criteria
  196.         If tbl!cost > 30 And tbl!cost < 40 Then
  197.         tbl.Edit
  198.         tbl!cost = tbl!cost * .9
  199.         tbl.Update
  200.         End If
  201.     Else
  202.         'Exit if past top of range
  203.         Exit Do
  204.     End If
  205.     'Get the next record
  206.     tbl.MoveNext
  207.     Loop
  208.     CommitTrans
  209.     'Stop the clock and report
  210.     TimeCount = GetTickCount() - TimeStart
  211.     Text1(0) = Format$(TimeCount / 1000, "##0.00")
  212.     CloseDb
  213.     'Dynaset FindFirst ---------------------------------------
  214.     'Start each iteration with same file
  215.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  216.     'Open the data logicals
  217.     OpenDb
  218.     'Start The Clock
  219.     TimeStart = GetTickCount()
  220.     'Use transactions for speed
  221.     BeginTrans
  222.     'Jump to first record
  223.     dyna.FindFirst "Id >= 5000"
  224.     'Continue searching till eof or break
  225.     Do Until dyna.EOF
  226.     'Test if reached top of range
  227.     If dyna!id < 6000 Then
  228.         'Test if record meets change criteria
  229.         If dyna!cost > 30 And dyna!cost < 40 Then
  230.         dyna.Edit
  231.         dyna!cost = dyna!cost * .9
  232.         dyna.Update
  233.         End If
  234.     Else
  235.         'Exit loop if past top of range
  236.         Exit Do
  237.     End If
  238.     'Get the next record
  239.     dyna.MoveNext
  240.     Loop
  241.     CommitTrans
  242.     'Stop the clock and report
  243.     TimeCount = GetTickCount() - TimeStart
  244.     Text1(1) = Format$(TimeCount / 1000, "##0.00")
  245.     CloseDb
  246.     'Test SQL processing with inline VB code ----------
  247.     'Start each iteration with same file
  248.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  249.     'Open the database logicals
  250.     OpenDb
  251.     'Start The Clock
  252.     TimeStart = GetTickCount()
  253.     'Execute the statement on databse DB
  254.     db.Execute "Update testtable Set Cost = Cost *.9 where cost > 30 and cost < 40 and id >= 5000 and id < 6000 and id/2 = id\2"
  255.     'Stop the clock and report
  256.     TimeCount = GetTickCount() - TimeStart
  257.     Text1(2) = Format$(TimeCount / 1000, "##0.00")
  258.     CloseDb
  259.     'Test SQL processing with Stored QueryDef -------
  260.     'Start each iteration with same file
  261.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  262.     'Open the database logicals
  263.     OpenDb
  264.     'Store the procedure before starting the clock
  265.     Set qd = db.CreateQueryDef("TestQd", "Update testtable Set Cost = Cost *.9 where cost > 30 and Cost < 40 and id >= 5000 and id < 6000")
  266.     qd.Close
  267.     'Start The Clock
  268.     TimeStart = GetTickCount()
  269.     'Use Transactions for speed
  270.     BeginTrans
  271.     'Execute the querydef on database DB
  272.     db.Execute "TestQd"
  273.     CommitTrans
  274.     'Stop the clock and report
  275.     TimeCount = GetTickCount() - TimeStart
  276.     Text1(3) = Format$(TimeCount / 1000, "##0.00")
  277.     'Remove the querydef - normally we wouldn't do this
  278.     db.DeleteQueryDef "TestQd"
  279.     CloseDb
  280.     'ParameterQueryDef ------------------------------------
  281.     'Start each iteration with same file
  282.     FileCopy "C:\vb\IoTest.bak", "C:\vb\IoTest.mdb"
  283.     'Open the database logicals
  284.     OpenDb
  285.     'Store the procedure before starting the clock
  286.     Set qd = db.CreateQueryDef("TestQd", "Parameters IdSearch1 Long, IdSearch2 Long, CostSearch1 IEEEDouble, CostSearch2 IEEEDouble; Update testtable Set Cost = Cost *.9 where cost > CostSearch1 and cost < CostSearch2 and id >= IdSearch1 and id < IdSearch2")
  287.     qd.Close
  288.     'Start the clock
  289.     TimeStart = GetTickCount()
  290.     BeginTrans
  291.     'Open the querydef
  292.     Set qd = db.OpenQueryDef("TestQd")
  293.     'Set the paramter values
  294.     qd!IdSearch1 = 5000
  295.     qd!IdSearch2 = 6000
  296.     qd!CostSearch1 = 30
  297.     qd!CostSearch2 = 40
  298.     'Execute the querydef
  299.     qd.Execute
  300.     CommitTrans
  301.     'Stop the clock and report
  302.     TimeCount = GetTickCount() - TimeStart
  303.     Text1(4) = Format$(TimeCount / 1000, "##0.00")
  304.     'Remove the querydef - normally we wouldn't do this
  305.     qd.Close
  306.     db.DeleteQueryDef "TestQd"
  307.     CloseDb
  308. 'Select Operations ======================================
  309. 'The objective of this benchmark is to read selected records From
  310. 'X to Y. For seeks and findfirst we need to get to X,then move
  311. 'through the records testing the criteria. For QueryDefs we need
  312. 'to select the desired records and then scan them all to achieve
  313. 'a similar result. Our criteria is all records with an even numbered
  314. 'ID between 5000 and 5100, for example 5000, 5002, 5004, etc.
  315. Case 1
  316.     Me.Caption = "VBench: Select Operation Benchmarks"
  317.     'Initialize and open the database logicals
  318.     OpenDb
  319.     'Table Seek -------------------------------------------------
  320.     'Start the clock
  321.     TimeStart = GetTickCount()
  322.     'Repeat the operation to get a meaningful time
  323.     For foo = 1 To 10
  324.     'Position to the first record with a seek
  325.     tbl.Seek "=", 5001
  326.     'Look at each record
  327.     For foobar = 1 To 98
  328.         If tbl!id / 2 = tbl!id \ 2 Then
  329.         'do something if it is even
  330.         End If
  331.         tbl.MoveNext
  332.     Next foobar
  333.     'Reset for next seek
  334.     tbl.Seek "=", 1
  335.     Next foo
  336.     'Stop the clock and report
  337.     TimeCount = GetTickCount() - TimeStart
  338.     Text1(0) = Format$(TimeCount / 1000, "##0.00")
  339.     'Dynaset FindFirst ---------------------------------------
  340.     dyna.MoveFirst
  341.     'Start The Clock
  342.     TimeStart = GetTickCount()
  343.     'This operation is slow enough we don't have to repeat it
  344.     'Jump to first record
  345.     dyna.FindFirst "Id = 5000"
  346.     For foo = 1 To 99
  347.     If dyna!id / 2 = dyna!id \ 2 Then
  348.         'do something if it is even
  349.     End If
  350.     dyna.MoveNext
  351.     Next foo
  352.     'We're positioned and ready to process, so stop benchmark
  353.     'Stop the clock and report
  354.     TimeCount = GetTickCount() - TimeStart
  355.     Text1(1) = Format$(TimeCount / 100, "##0.00")
  356.     'Inline VB SQL Code ------------------------------------
  357.     'Start The Clock
  358.     TimeStart = GetTickCount()
  359.     For foo = 1 To 10
  360.     'Execute the statement on databse DB
  361.     dyna.Close
  362.     Set dyna = db.CreateDynaset("Select * From Testtable where Id >= 5000 and Id < 5100 and Id \ 2 = Id / 2")
  363.     Do Until dyna.EOF
  364.         dyna.MoveNext
  365.     Loop
  366.     Next foo
  367.     'Stop the clock and report
  368.     TimeCount = GetTickCount() - TimeStart
  369.     Text1(2) = Format$(TimeCount / 1000, "##0.00")
  370.     'Static QueryDef ------------------------------------------
  371.     'Store the procedure before starting the clock
  372.     Set qd = db.CreateQueryDef("TestQd", "Select * From TestTable where Id >= 5000 and Id < 5100 and Id \ 2 = Id / 2")
  373.     qd.Close
  374.     'Start The Clock
  375.     TimeStart = GetTickCount()
  376.     For foo = 1 To 10
  377.     'Execute the querydef on database DB
  378.     dyna.Close
  379.     Set dyna = db.CreateDynaset("TestQd")
  380.     Do Until dyna.EOF
  381.         dyna.MoveNext
  382.     Loop
  383.     Next foo
  384.     'Stop the clock and report
  385.     TimeCount = GetTickCount() - TimeStart
  386.     Text1(3) = Format$(TimeCount / 1000, "##0.00")
  387.     'Remove the QueryDef
  388.     db.DeleteQueryDef ("TestQd")
  389.     'Parameter QueryDef ------------------------------------
  390.     'Init the db
  391.     CloseDb
  392.     OpenDb
  393.     'Store the procedure before starting the clock
  394.     Set qd = db.CreateQueryDef("TestQd", "Parameters IDSearch1 Long, IDSearch2 Long; Select * From Testtable where id >= IDSearch1 and Id < IdSearch2 and Id \ 2 = Id / 2")
  395.     qd.Close
  396.     'Start the clock
  397.     TimeStart = GetTickCount()
  398.     For foo = 1 To 10
  399.     'Open the querydef
  400.     Set qd = db.OpenQueryDef("TestQd")
  401.     'Set the paramter values
  402.     qd!IdSearch1 = 5000
  403.     qd!IdSearch2 = 5100
  404.     'Build the dynaset from the querydef
  405.     dyna.Close
  406.     'Note the required alternate syntax!
  407.     Set dyna = qd.CreateDynaset()
  408.     Do Until dyna.EOF
  409.         dyna.MoveNext
  410.     Loop
  411.     'Close the querydef
  412.     qd.Close
  413.     Next foo
  414.     'Stop the clock and report
  415.     TimeCount = GetTickCount() - TimeStart
  416.     Text1(4) = Format$(TimeCount / 1000, "##0.00")
  417.     'Remove the QueryDef
  418.     db.DeleteQueryDef ("TestQd")
  419.     CloseDb
  420. 'Populate the DB Test Set ============================================
  421. Case 2
  422.     Me.Caption = "VBench: Populate Database"
  423.     'Initialize costs so we'll have a nice variety
  424.     cost(1) = 19.95
  425.     cost(2) = 29.95
  426.     cost(3) = 39.95
  427.     cost(4) = 49.95
  428.     cost(5) = 9.95
  429.     'Use transactions for speed
  430.     BeginTrans
  431.     OpenDb
  432.     db.Execute "Delete * from TestTable"
  433.     For foo = 1 To 10000
  434.     foobar = foobar + 1
  435.     If foobar > 5 Then foobar = 1
  436.     tbl.AddNew
  437.     tbl!cost = cost(foobar)
  438.     tbl!id = foo
  439.     tbl.Update
  440.     Next foo
  441.     CommitTrans
  442.     CloseDb
  443. 'Exit the program ====================================================
  444. Case 3
  445.     Screen.MousePointer = 0
  446.     End
  447. End Select
  448. Screen.MousePointer = 0
  449. End Sub
  450. Sub OpenDb ()
  451. On Error GoTo 0
  452.     'Open the logicals
  453.     Set db = OpenDatabase("C:\vb\IoTest.mdb")
  454.     Set tbl = db.OpenTable("TestTable")
  455.     tbl.Index = "IdKey"
  456.     Set dyna = db.CreateDynaset("TestTable")
  457. End Sub
  458.